package com.vhackandroid.bremen.quizbox;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SingleDeviceActivity extends Activity {
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.singledeviceactivity_layout);
		
		final EditText player1NameText = (EditText) findViewById(R.id.player1NameText);
		final EditText player2NameText = (EditText) findViewById(R.id.player2NameText);
		
		final SharedPreferences namePreferences = getSharedPreferences("names", MODE_PRIVATE);
		String player1Name = namePreferences.getString("player1", "Player1");
		String player2Name = namePreferences.getString("player2", "Player2");
		
		player1NameText.setText(player1Name);
		player2NameText.setText(player2Name);
		
		Button startButton = (Button) findViewById(R.id.singledeviceStartButton);
		startButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Editor editor = namePreferences.edit();
				if(!player1NameText.getText().toString().isEmpty()){
					editor.putString("player1", player1NameText.getText().toString());
				}
				if(!player2NameText.getText().toString().isEmpty()){
					editor.putString("player2", player2NameText.getText().toString());
				}
				editor.commit();
				Intent quizIntent = new Intent(SingleDeviceActivity.this, QuizActivity.class);
				quizIntent.putExtra("flag", 0);
				startActivity(quizIntent);
			}
		});
		
	}
}